<script>
	import store from "./store";
	import {
		getItem
	} from "./pages/util/storageHelper";
	import wfc from "./wfc/client/wfc";
	import avengineKit from "./wfc/av/engine/avengineKit";
	import conferenceManager from "./pages/voip/conference/conferenceManager";
	import ConferenceInviteMessageContent from "./wfc/av/messages/conferenceInviteMessageContent";
	import Message from "./wfc/messages/message";
	import ForwardType from "./pages/conversation/message/forward/ForwardType";

	export default {
		data() {
			return {
				wfc: null,
				avengineKit: null,
				store: null,
				conferenceManager: null,
			}
		},
		onLaunch: function() {
			console.log("App Launch");
			this.wfc = wfc;
			this.avengineKit = avengineKit;
			this.store = store;
			this.conferenceManager = conferenceManager;
			// #ifdef APP-PLUS
			plus.push.getClientInfoAsync((info) => {
				let cid = info["clientid"];
				if (cid) {
					console.log('push clientId', cid);
					wfc.setDeviceToken(7, cid);
				}
			});
			// #endif
			uni.onTabBarMidButtonTap(() => {
				uni.navigateTo({
					url: '/pages/workspace/WorkspacePage',
				});
			})
		},
		onShow: function() {
			console.log("App Show");
			store.state.misc.isAppHidden = false;
			// #ifdef H5
			let userId = getItem('userId');
			let token = getItem('token')
			if (token) {
				wfc.connect(userId, token);
				this.go2ConversationList();
			} else {
				uni.redirectTo({
					url: '/pages/login/LoginPage',
				})
			}
			// #endif
		},
		onHide: function() {
			console.log("App Hide");
			store.state.misc.isAppHidden = true;
		},
		methods: {
			go2ConversationList() {
				uni.switchTab({
					url: '/pages/conversationList/ConversationListPage',
					success: () => {
						console.log('to conversation list success');
					},
					fail: e => {
						console.log('to conversation list error', e);
					},
					complete: () => {
						console.log('switch tab complete')
					}
				});
			},

			forwardConferenceInviteMessage(callId, host, title, desc, startTime, audioOnly, defaultAudience, advance, pin) {
				let inviteMessageContent = new ConferenceInviteMessageContent(callId, host, title, desc, startTime, audioOnly,
					defaultAudience, advance, pin);
				console.log('invite', inviteMessageContent);
				let message = new Message(null, inviteMessageContent);
				this.$forward({
					forwardType: ForwardType.NORMAL,
					messages: [message]
				});
			},
		}
	}
</script>

<style lang="css">
	/*每个页面公共css */
	@import './global.css';
	@import './wfc.css';
	/* #ifndef APP-NVUE */
	@import './static/iconfonts/customicons.css';
	@import './static/iconfonts/icomoon/style.css';
	/* #endif */

	:root {
		--uni-tabbar-height: 50px;
		/*app-plus header 和 tabbar 是原生的*/
		/* #ifdef APP-PLUS */
		--uni-page-header-height: 0;
		--page-full-height-without-header-and-tabbar: 100vh;
		--page-full-height-without-header: 100vh;
		/* #endif */
		/* #ifdef H5 */
		--uni-page-header-height: 44px;
		--page-full-height-without-header-and-tabbar: calc(100vh - 44px - 50px);
		--page-full-height-without-header: calc(100vh - 44px);
		/* #endif */
	}
	.conversation-rq {
		width: calc(100% - 20px);
		padding: 2px;
		margin: 10px;
		border-radius: 10px;
		background-color: #ffffff;
		font-size: 16px;
	}
	.rq-hine {
		width: 100%;
		height: 2px;
		position: relative;
	}
	.rq-hine2 {
		width: 100%;
		height: 2px;
		position: relative;
	}

	.rq-hine::after {
		content: "";
		position: absolute;
		left: 65px;
		right: 0;
		bottom: 0;
		border-bottom: 1px solid #f4f4f4;
	}
	.rq-hine2::after {
		content: "";
		position: absolute;
		left: 0;
		right: 0;
		bottom: 0;
		border-bottom: 1px solid #f4f4f4;
	}
	.rq-tc .tz {
	    width: 100%;
	    height: 20vh;
			background: rgba(56, 107, 246, 0);
	    position: absolute;
	    top: 0;
	    left: 0;
	}
	.rq-tc .tc {
	    width: 100%;
	    height: 80vh;
	    background: #FFF;
	    position: absolute;
	    bottom: 0;
	    left: 0;
	    border-radius: 20px 20px 0px 0px;
	    padding: 15px 20px;
	    overflow-y: auto;
	}
	
	.rq-tc .tc .tch {
	    margin-top: 60px;
	    width: 100%;
	    height: 46px;
	    border-radius: 10px;
	    background: #386BF6;
	    display: flex;
	    justify-content: center;
	    align-items: center;
	    color: #FFF;
	    font-family: MiSans;
	    font-size: 16px;
	    font-style: normal;
	    font-weight: 400;
	    line-height: normal;
	}
	
	.rq-tc .tc .tcg {
	    text-align: center;
	    margin-top: 18px;
	    width: 100%;
	    color: #999;
	    font-family: MiSans;
	    font-size: 12px;
	    font-style: normal;
	    font-weight: 400;
	    line-height: normal;
	}
	
	.rq-tc .tc .tcf {
	    text-align: center;
	    margin-top: 28px;
	    width: 100%;
	}
	
	.rq-tc .tc .tcf .tcf1 {
	    width: 160px;
	    height: 160px;
	}
	
	.rq-tc .tc .tce {
	    text-align: center;
	    margin-top: 1px;
	    width: 100%;
	    color: #BCBDBD;
	    font-family: MiSans;
	    font-size: 14px;
	    font-style: normal;
	    font-weight: 400;
	    line-height: normal;
	    letter-spacing: -0.72px;
	}
	
	.rq-tc .tc .tcd {
	    text-align: center;
	    margin-top: 5px;
	    width: 100%;
	    color: #21252A;
	    font-family: MiSans;
	    font-size: 18px;
	    font-style: normal;
	    font-weight: 600;
	    line-height: normal;
	}
	
	.rq-tc .tc .tcc {
	    text-align: center;
	    margin-top: 28px;
	    width: 100%;
	}
	
	.rq-tc .tc .tcc .tcc1 {
	    width: 75px;
	    height: 75px;
	    border-radius: 50%;
	    margin: 0 auto;
	}
	
	.rq-tc .tc .tcb {
	    margin-top: 25px;
	    display: flex;
	    justify-content: space-between;
	    align-items: center;
	}
	
	.rq-tc .tc .tcb .tcb2 {
	    width: 22px;
	    height: 22px;
	}
	
	.rq-tc .tc .tcb .tcb1 {
	    color: #21252A;
	    text-align: center;
	    font-family: MiSans;
	    font-size: 18px;
	    font-style: normal;
	    font-weight: 600;
	    line-height: normal;
	}
	
	.rq-tc .tc .tca {
	    width: 38px;
	    height: 4px;
	    border-radius: 10px;
	    background: #E7E7E7;
	    margin: 0 auto;
	}
	
	.rq-tc {
	    position: fixed;
	    top: 0;
	    left: 0;
	    bottom: 0;
	    right: 0;
	    width: 100%;
	    height: 100%;
	    background: rgba(0, 0, 0, 0.7);
	}
</style>